import React from 'react';
import { Button,Modal } from "antd";
import { connect } from 'dva';
import { G2SampleChart } from '@/components/chart/SampleChart';

const namespace = 'sample_chart';
const mapStateToProps = state =>{
    return {
        state:state[namespace]
    }
}
const mapDispatchToProps = dispatch =>{
    return {
        dispatch:dispatch
    }
}

@connect(mapStateToProps,mapDispatchToProps)
class TestSampleChart extends React.Component<any,any> {
    state={
        statisticVisible:false,
    }
    constructor(props){
        super(props);
    }

    showStatistic(){
        this.props.dispatch({type:`${namespace}/getStatistic`});
        this.setState({statisticVisible: true});
    }

    handleStatisticCancel = () => {
        this.setState({
          statisticVisible: false,
        });
      }

    render() {
        return (
        <div>
            <Button onClick={() => this.showStatistic()}>图表</Button>
            <Modal visible={this.state.statisticVisible} footer={null} onCancel={this.handleStatisticCancel}>
                <G2SampleChart data={this.props.state.dataSource} />
            </Modal>
        </div>);
    }
}

export default TestSampleChart;
